import re
from playwright.sync_api import Playwright, sync_playwright, expect


output_file = './screenshots/login.png'
def run(playwright: Playwright) -> None:

    browser = playwright.chromium.launch(headless=False)
    context = browser.new_context()
    page = context.new_page()
    page.goto("http://192.168.0.173:8088/login")
    page.get_by_placeholder("请输入用户名").click()
    page.get_by_placeholder("请输入用户名").fill("cross")
    page.get_by_placeholder("请输入用户名").press("Tab")
    page.get_by_placeholder("请输入密码").fill("abcd1234")
    page.screenshot(path=output_file, full_page=True)
    page.get_by_placeholder("请输入密码").press("Enter")
    page.get_by_role("link", name="跨链网关").click()
    page.get_by_role("button", name="tcip-fabric20250116143212").click()
    expect(page.get_by_text("tcip-fabric20250116143212").nth(1)).to_be_visible()
    page.get_by_text("接入申请").click()
    expect(page.get_by_text("申请通过")).to_be_visible()
    expect(page.locator("tbody")).to_contain_text("tcip-fabric20250116143212")
    page.get_by_title("tcip-fabric20250116143212").click()
    expect(page.get_by_title("tcip-fabric20250116143212")).to_be_visible()
    page.get_by_text("子链信息").click()
    page.get_by_text("fabric20250116143214").click()
    page.get_by_text("事件配置信息").click()

    # ---------------------
    context.close()
    browser.close()


with sync_playwright() as playwright:
    run(playwright)
